package com.example.newhabitclock.CalendarView

import android.content.Context
import android.os.Build
import android.util.Log
import androidx.annotation.RequiresApi
import androidx.core.content.ContextCompat
import com.example.newhabitclock.R
import com.prolificinteractive.materialcalendarview.CalendarDay
import com.prolificinteractive.materialcalendarview.DayViewDecorator
import com.prolificinteractive.materialcalendarview.DayViewFacade
import java.time.DateTimeException
import java.time.LocalDate

class RedCircleDecorator(
    context: Context, private val dates: Set<CalendarDay> //HushSet中保存日期数据节省效率，格式必须为"yyyy-MM-dd"
) : DayViewDecorator {
    //红圈icon需要修改
    private val drawable = ContextCompat.getDrawable(context, R.drawable.ic_reset)

    @RequiresApi(Build.VERSION_CODES.O)
    override fun shouldDecorate(day: CalendarDay): Boolean {
        return try {
            //判断是否为打了卡的日期 是则红圈用圈起来(在decorate方法中实现)
            return dates.contains(day)
        } catch (e: DateTimeException) {
            false // 跳过无效日期
        }
    }

    override fun decorate(view: DayViewFacade) {
        drawable?.let { view.setBackgroundDrawable(it) }
    }
}